package com.villaday.idf.fragment3;


import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import androidx.annotation.RequiresApi;
import com.google.android.material.appbar.AppBarLayout;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidkun.xtablayout.XTabLayout;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.villaday.idf.R;
import com.villaday.idf.activity.BackHandlerHelper;
import com.villaday.idf.activity.FragmentBackHandler;
import com.villaday.idf.activity.Home_temaiSearchActivity;
import com.villaday.idf.activity.HouseDetailsActivityFor3;
import com.villaday.idf.adapter2.HomeTeMaiAdapter;

import com.villaday.idf.adapter3.HomeExtraTemaiAdapter;
import com.villaday.idf.adapter3.TeMaiAreaAdapter;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.BaseFragment;
import com.villaday.idf.base.BaseRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.AutoScrollViewPager;
import com.villaday.idf.custom.AutoScrollViewPagerVipCanscro;
import com.villaday.idf.custom.CustomPopupWindow;
import com.villaday.idf.custom.LoadDialog;
import com.villaday.idf.custom.NavView;
import com.villaday.idf.custom.pop.SharePop;
import com.villaday.idf.fragment.OrdinaryVipFragment;
import com.villaday.idf.model2.Presell_list;
import com.villaday.idf.model3.AllPostersEntity;
import com.villaday.idf.model3.ConfigsEntity;
import com.villaday.idf.model3.HomeDetailsEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.JumpUtils;
import com.villaday.idf.util.LogUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.ShareUtils;
import com.villaday.idf.util.ToastUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import byc.imagewatcher.ImageWatcher;
import io.reactivex.functions.Consumer;
import me.bakumon.statuslayoutmanager.library.OnStatusChildClickListener;
import me.bakumon.statuslayoutmanager.library.StatusLayoutManager;

/**
 * 特卖首页
 */
public class TeMaiFragment extends BaseFragment implements OnAdapterCallbackListener, FragmentBackHandler {


    @BindView(R.id.xTablayout)
    XTabLayout mXTabLayout;
    @BindView(R.id.rv_home_extra)
    RecyclerView rvHomeExtra;
    @BindView(R.id.activity_main_app_bar)
    AppBarLayout appBarLayout;
    @BindView(R.id.rv_sale)
    RecyclerView rvSale;
    @BindView(R.id.srl)
    SwipeRefreshLayout srl;

    @BindView(R.id.tv_tm_area)
    TextView tvTmArea;
    @BindView(R.id.iv_tm_area)
    ImageView ivTmArea;
    @BindView(R.id.tv_tm_select)
    TextView tvTmSelect;


    private ImageWatcher vImageWatcher;
    private AllPostersEntity.BodyBean allPostersEntity;

    private HomeDetailsEntity.BodyBean mBodyDetailsEntity;
    private HomeExtraTemaiAdapter mHomeExtraAdapter;
    private List<ConfigsEntity.BodyBean.RegionsBean> mRegions;
    private List<ConfigsEntity.BodyBean.TagsBean> mTags;
    private HomeTeMaiAdapter hometype2Adapter;

    private int pageNo = 1;
    private int nextIndex = 1;
    private int pageSize = 10;
    private int mSortsPosition = 0;//排序
    private int mPagePosition = 0;//超值特卖
    private int mSidPosition = 0;//城市

    private LoadDialog mLoadDialog;
    private List<Presell_list.BodyBean.ListBean> data = new ArrayList<>();
    private OrdinaryVipFragment.Jumps jumps;
    private TamaiMidAdvAdapter vipMidAdvAdapter;
    private OrdinaryVipFragment.OnViplPageListener VPListener;
    private AutoScrollViewPagerVipCanscro viewPager;
    private NavView navView;
    private RelativeLayout rl_head;
    private StatusLayoutManager statusLayoutManager;

    private List<ConfigsEntity.BodyBean.SortsBean> mSorts;
    private CustomPopupWindow mPopurArea;
    private TeMaiAreaAdapter mHomeAreaAdapter;
    private boolean mIsHide = false;
    private Gson gson = new GsonBuilder().disableHtmlEscaping().create();

    public TeMaiFragment() {
        // Required empty public constructor
    }

    public static TeMaiFragment instance() {
        TeMaiFragment teMaiFragment = new TeMaiFragment();
        return teMaiFragment;
    }

    @Override
    protected int getViewResId() {
        return R.layout.fragment_te_mai;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void init(View v) {
        initSharePop();
        statusLayoutManager = setupDefaultStatusLayoutManager(srl, new OnStatusChildClickListener() {
            @Override
            public void onEmptyChildClick(View view) {
                getHomeDetails();
            }

            @Override
            public void onErrorChildClick(View view) {
                getHomeDetails();
            }

            @Override
            public void onCustomerChildClick(View view) {

            }
        });

        srl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                pageNo = 1;
                nextIndex = 1;
                if (mBodyDetailsEntity.getSites() != null && mBodyDetailsEntity.getSites() != null && mBodyDetailsEntity.getCategories() != null && mBodyDetailsEntity.getCategories() != null) {
                    initSale();
                } else {
                    srl.setRefreshing(false);
                }
            }
        });

        getHomeDetails();

        initFragment();

        getCity();
    }

    private void initFragment() {
        //特卖
        rvHomeExtra.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayout.HORIZONTAL, false));
        mHomeExtraAdapter = new HomeExtraTemaiAdapter(getActivity());
        mHomeExtraAdapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                if (mTags != null) {
                    for (int i = 0; i < mTags.size(); i++) {
                        if (i == position) {
                            mTags.get(i).setCheck(true);
                        } else {
                            mTags.get(i).setCheck(false);
                        }
                    }
                    mHomeExtraAdapter.notifyDataSetChanged();
                }

                //重新请求数据
                pageNo = 1;
                nextIndex = 1;
                mPagePosition = position;
                showDialog();
                initSale();

            }
        });
        rvHomeExtra.setAdapter(mHomeExtraAdapter);
        mXTabLayout.setOnTabSelectedListener(new XTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(XTabLayout.Tab tab) {
                if (mIsHide && mSidPosition == 0) {
                    mIsHide = false;
                } else {
                    mSidPosition = tab.getPosition();
                    //重新请求数据
                    pageNo = 1;
                    nextIndex = 1;
                    showDialog();
                    initSale();
                }

            }

            @Override
            public void onTabUnselected(XTabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(XTabLayout.Tab tab) {
                tvTmSelect.setVisibility(View.VISIBLE);
                mSidPosition = 0;
                pageNo = 1;
                nextIndex = 1;
                dismissDialogAndRefresh();
                showDialog();
                initSale();
            }
        });
        //特卖列表
        hometype2Adapter = new HomeTeMaiAdapter(getContext(), this, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               /* Intent intent = new Intent(getContext(), HouseDetailsActivityFor3.class);
                intent.putExtra("type", 1);
                intent.putExtra("houseId", data.get((Integer) v.getTag()).getId());
                intent.putExtra("presellProduct", true);
                intent.putExtra("brokerAge", data.get((Integer) v.getTag()).getBrokerAgeAmountValue());
                intent.putExtra("persellId", data.get((Integer) v.getTag()).getId());
                startActivity(intent);*/

////2 小区，3 房源 ，7 酒店，52 特卖(预售)
                ShareUtils.getData(TeMaiFragment.this, (AppCompatActivity) getActivity(), "52", data.get((Integer) v.getTag()).getId());
            }
        });
        View head = View.inflate(getContext(), R.layout.item_temai_head, null);
        initHead(head);
        hometype2Adapter.addHeaderView(head);

        hometype2Adapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                Intent intent = new Intent(getContext(), HouseDetailsActivityFor3.class);
                intent.putExtra("type", 0);
                intent.putExtra("houseId", data.get(position).getId());
                intent.putExtra("presellProduct", true);
                intent.putExtra("brokerAge", data.get(position).getRebateAmount());
                intent.putExtra("persellId", data.get(position).getId());
                startActivity(intent);
            }
        });
        rvSale.setLayoutManager(new LinearLayoutManager(getContext()));
        rvSale.setAdapter(hometype2Adapter);
    }


    private void getCity() {
        Map<String, String> map = new HashMap<>();
        map.put("pageId", "00001");
        OkHttpUtil.getJSON(getActivity(), Constant.URL.configs, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);

                    ConfigsEntity configsEntity = gson.fromJson(json, ConfigsEntity.class);
                    if (configsEntity.getCode().equals(Constant.Strings.SUC)) {
                        mRegions = configsEntity.getBody().getRegions();
                        initTab();

                        mSorts = configsEntity.getBody().getSorts();
                        mTags = configsEntity.getBody().getTags();
                        mTags.get(0).setCheck(true);
                        mHomeExtraAdapter.setDatas(mTags);
                        initSale();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFailure(String url, String error) {
            }
        });
    }

    private void initSharePop() {
        mRxManager.on("sharepopEntity", new Consumer<AllPostersEntity.BodyBean>() {

            @Override
            public void accept(AllPostersEntity.BodyBean bodyBean) throws Exception {
                allPostersEntity = bodyBean;
            }
        });
        mRxManager.on("sharepop", new Consumer<ImageWatcher>() {
            @Override
            public void accept(ImageWatcher imageWatcher) throws Exception {
                vImageWatcher = imageWatcher;
                vImageWatcher.setImageWatcherOndismiss(new ImageWatcher.ImageWatcherDiss() {
                    @Override
                    public void onImageWatcherDiss() {
                        if (allPostersEntity != null) {
                            SharePop sharePop = new SharePop(TeMaiFragment.this, getActivity(), getActivity(), allPostersEntity);
                            sharePop.showPopupWindow();
                        }
                    }
                });
            }
        });
    }

    @Override
    public boolean onBackPressed() {
        if (vImageWatcher == null) {
            return false;
        } else {
            // 当确认没有子Fragmnt时可以直接return false
            if (!vImageWatcher.handleBackPressed()) {
                return BackHandlerHelper.handleBackPress(this);
            } else {
                return !BackHandlerHelper.handleBackPress(this);
            }
        }
    }

    private void initHead(View head) {
        viewPager = head.findViewById(R.id.vp_homeAd);
        navView = head.findViewById(R.id.nv_homeAd);
        rl_head = head.findViewById(R.id.rl_head);
    }

    @OnClick({R.id.iv_search, R.id.tv_tm_area, R.id.iv_tm_area, R.id.tv_tm_select})
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.iv_search:
                startActivity(new Intent(getContext(), Home_temaiSearchActivity.class));
                break;
            case R.id.tv_tm_area:
            case R.id.iv_tm_area:
                initPopular(v);
                break;
            case R.id.tv_tm_select:
                tvTmSelect.setVisibility(View.GONE);
                if (mXTabLayout.getSelectedTabPosition() != 0) {
                    mIsHide = true;
                    mXTabLayout.getTabAt(0).select();
                }
                break;
        }
    }


    /**
     * 初始化Popular
     *
     * @param view
     */
    public void initPopular(View view) {
        if (mPopurArea == null) {
            mPopurArea = new CustomPopupWindow.Builder().setheight(LinearLayoutCompat.LayoutParams.MATCH_PARENT)
                    .setwidth(LinearLayoutCompat.LayoutParams.MATCH_PARENT)
                    .setOutSideCancel(false)
                    .setContext(getContext())
                    .setActivity(getActivity())
                    .isBlur(true)
                    .setRadius(5)
                    .setContentView(R.layout.popu_bourn_head_chose_addr_sort)
                    .setOnDismissListener(new PopupWindow.OnDismissListener() {
                        @Override
                        public void onDismiss() {
                            mPopurArea = null;
                        }
                    })
                    .builder();
            mPopurArea.getItemView(R.id.close).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mPopurArea.dismiss();
                }
            });
            RecyclerView rvArea = (RecyclerView) mPopurArea.getItemView(R.id.rv_addr_sort);
            mHomeAreaAdapter = new TeMaiAreaAdapter(getActivity());
            rvArea.setLayoutManager(new LinearLayoutManager(getContext()));
            rvArea.setAdapter(mHomeAreaAdapter);
            mHomeAreaAdapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    try {
                        for (int i = 0; i < mSorts.size(); i++) {
                            if (i == position) {
                                mSorts.get(i).setCheck(true);
                            } else {
                                mSorts.get(i).setCheck(false);
                            }
                        }
                        mHomeAreaAdapter.setData(mSorts);
                        tvTmArea.setText(mSorts.get(position).getName());
                        //查询地区
                        mSortsPosition = position;
                        pageNo = 1;
                        initSale();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    mPopurArea.dismiss();
                }
            });
            mHomeAreaAdapter.setData(mSorts);
            if (view.getId() == R.id.tv_toolbar_home_area || view.getId() == R.id.iv_toolbar_home_area) {
                mPopurArea.showAsLaction(appBarLayout, Gravity.BOTTOM, 0, 0);
            } else {
                mPopurArea.showAsLaction(appBarLayout, Gravity.BOTTOM, 0, 0);
            }
        } else {
            mPopurArea.dismiss();
        }
    }


    /**
     * 初始化超值特卖
     */
    private void initSale() {
        if (mSorts == null || mTags == null || mRegions == null) {
            return;
        }

        Map<String, String> map = new HashMap<>();
        map.put("pageNo", pageNo + "");
        map.put("pageSize", pageSize + "");
//        map.put("query", mBodyDetailsEntity.getCategories().get(currentPagePosition).getQuery());
//        map.put("sid", mBodyDetailsEntity.getSites().get(currentPagePositionSid).getQuery().replace("sid=", ""));
        map.put("sortBy", mSorts.get(mSortsPosition).getValue());
        map.put("tag", mTags.get(mPagePosition).getValue());
        map.put("region", mRegions.get(mSidPosition).getValue());
        LogUtil.jLog().e(gson.toJson(map));
        OkHttpUtil.getJSON(getContext(), Constant.URL.preSales, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                LogUtil.jLog().e(json);

                removeLoadingItem();
                if (pageNo == 1) {
                    data.clear();
                }
                LogUtil.jLog().e(json);
                dismissDialogAndRefresh();
                Presell_list presell_list = new Gson().fromJson(json, Presell_list.class);

                if ("200".equals(presell_list.getCode()) && presell_list.getBody().getList() != null) {
                   /* if (pageNo == 1 && presellEntity.getBody().getRecomendList() != null && presellEntity.getBody().getRecomendList().getList() != null) {

                        dataHead.addAll(presellEntity.getBody().getRecomendList().getList());
                        homeListSaleHeadAdapter.setData(dataHead);
                    }*/

                    data.addAll(presell_list.getBody().getList());
                    if (data.size() > 0) {
                        data.get(0).setMyType(3);
                    }
                    if (presell_list.getBody().isHasNext()) {
                        data.add(new Presell_list.BodyBean.ListBean(1));
                        nextIndex = pageNo + 1;

                    } else {
                        addBaseLine();
                    }
                    if (data.size() > 0) {
                        statusLayoutManager.showSuccessLayout();

                    } else {
                        statusLayoutManager.showEmptyLayout();

                    }
                } else {
                    addBaseLine();
                    statusLayoutManager.showEmptyLayout();
                }
                hometype2Adapter.setData(data);


            }

            @Override
            public void onFailure(String url, String error) {
                dismissDialogAndRefresh();
                if (statusLayoutManager != null) {

                    statusLayoutManager.showErrorLayout();
                }
                ToastUtil.initToast(getContext(), "网络错误");
            }
        });
    }

    /**
     * 获取区域  等标签
     */
    private void getHomeDetails() {
        OkHttpUtil.getJSON(getContext(), Constant.URL.saleconfigurations, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                LogUtil.jLog().e(json);
                HomeDetailsEntity homeDetailsEntity = new Gson().fromJson(json, HomeDetailsEntity.class);
                if ("200".equals(homeDetailsEntity.getCode())) {
                    mBodyDetailsEntity = homeDetailsEntity.getBody();

                    //中间广告位
                    if (mBodyDetailsEntity.getMiddleAdverts() != null && mBodyDetailsEntity.getMiddleAdverts().size() > 0) {

                        viewPager.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                                (int) (PhoneUtil.getPhoneWidth(getContext()) / 5.4)));
                        vipMidAdvAdapter = new TamaiMidAdvAdapter(jumps, VPListener);
                        viewPager.setAdapter(vipMidAdvAdapter);
                        viewPager.setSlideBorderMode(AutoScrollViewPager.SLIDE_BORDER_MODE_CYCLE);
                        viewPager.setInterval(2300);
                        viewPager.setAutoScrollDurationFactor(4);
                        viewPager.setOnTouchListener(new View.OnTouchListener() {
                            @Override
                            public boolean onTouch(View v, MotionEvent event) {
                                switch (event.getAction()) {
                                    case MotionEvent.ACTION_MOVE:
                                        break;
                                    case MotionEvent.ACTION_UP:
                                    case MotionEvent.ACTION_CANCEL:
                                        break;
                                }
                                return false;
                            }
                        });

                        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                            @Override
                            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                            }

                            @Override
                            public void onPageSelected(int position) {
                                try {
                                    if (navView == null) {
                                        return;
                                    }
                                    if (position == 0) {
                                        navView.setCurrentItem(mBodyDetailsEntity.getMiddleAdverts().size() - 1);
                                    } else if (position == mBodyDetailsEntity.getMiddleAdverts().size() + 1) {
                                        navView.setCurrentItem(0);
                                    } else {
                                        navView.setCurrentItem(position - 1);
                                    }
                                } catch (Exception e) {
                                    Log.e("TAG", "onPageSelected: " + e.getMessage());

                                }

                            }

                            @Override
                            public void onPageScrollStateChanged(int state) {
                                if (viewPager == null) {
                                    return;
                                }
                                if (state == 0) {
                                    if (viewPager.getCurrentItem() == mBodyDetailsEntity.getMiddleAdverts().size() + 1) {
                                        viewPager.setCurrentItem(1, false);
                                    } else if (viewPager.getCurrentItem() == 0) {
                                        viewPager.setCurrentItem(mBodyDetailsEntity.getMiddleAdverts().size(), false);
                                    }
                                }

                            }
                        });
                        vipMidAdvAdapter.setData(mBodyDetailsEntity.getMiddleAdverts());
                    } else {
                        viewPager.setVisibility(View.GONE);
                    }

                }
            }


            @Override
            public void onFailure(String url, String error) {
                dismissDialogAndRefresh();
                if (statusLayoutManager != null) {

                    statusLayoutManager.showErrorLayout();
                }
                ToastUtil.initToast(getContext(), "网络错误");
            }
        });
    }

    private void initTab() {
        if (mRegions != null) {
            for (int i = 0; i < mRegions.size(); i++) {
                mXTabLayout.addTab(mXTabLayout.newTab().setText(mRegions.get(i).getName()));
            }
        }


        //TabLayoutUtils.reflex(tab, 5);
    }

    /**
     * 设置加载框
     */
    protected void showDialog() {

        mLoadDialog = LoadDialog.newInstance("加载中");


        mLoadDialog.show(getActivity().getSupportFragmentManager(), "loading");
    }

    /**
     * 停止加载框
     */
    protected void dismissDialogAndRefresh() {
        if (mLoadDialog != null) {
            mLoadDialog.dismiss();//获取信息后关闭对话框
        }
        if (srl != null && srl.isRefreshing()) {
            srl.setRefreshing(false);
        }
    }

    @Override
    public void onCallback() {

        if (nextIndex == pageNo + 1) {
            pageNo++;
            initSale();
        }
    }

    private void removeLoadingItem() {
        if (data.size() > 0) {
            if (data.get(data.size() - 1).getMyType() == 1) {
                data.remove(data.size() - 1);
            }
        }
    }

    private void addBaseLine() {
        if (pageNo != 1) {
            data.add(new Presell_list.BodyBean.ListBean(2));
        }
    }

    //广告位
    public class TamaiMidAdvAdapter extends PagerAdapter {

        private List<SimpleDraweeView> imgData;
        private OrdinaryVipFragment.Jumps jumps;
        private OrdinaryVipFragment.OnViplPageListener vpListener;

        public TamaiMidAdvAdapter(OrdinaryVipFragment.Jumps jumps, OrdinaryVipFragment.OnViplPageListener vpListener) {

            this.jumps = jumps;
            this.vpListener = vpListener;
        }

        public void setData(List<HomeDetailsEntity.BodyBean.MiddleAdvertsBean> data) {
            if (imgData == null) {
                imgData = new ArrayList<>();
            } else {
                imgData.clear();
            }
            if (navView == null) {
                return;
            }
            navView.setCount(data.size());
            if (data.size() > 1) {
                imgData.add(initSDV(data.get(data.size() - 1).getJumpType(), data.get(data.size() - 1).getUrl(), jumps, vpListener, data.get(data.size() - 1).getMiniAppId(), data.get(data.size() - 1).getMiniProgramType(), data.size() - 1, data.get(data.size() - 1).getMaterial().getUrl()));
            }
            for (int i = 0; i < data.size(); i++) {
                imgData.add(initSDV(data.get(i).getJumpType(), data.get(i).getUrl(), jumps, vpListener, data.get(i).getMiniAppId(), data.get(i).getMiniProgramType(), i, data.get(i).getMaterial().getUrl()));
            }
            if (data.size() > 1) {
                imgData.add(initSDV(data.get(0).getJumpType(), data.get(0).getUrl(), jumps, vpListener, data.get(0).getMiniAppId(), data.get(0).getMiniProgramType(), 0, data.get(0).getMaterial().getUrl()));
            }
            this.notifyDataSetChanged();
        }


        public SimpleDraweeView initSDV(final int JumpType, final String url, final OrdinaryVipFragment.Jumps jumps, final OrdinaryVipFragment.OnViplPageListener VPListener, final String MiniAppId, final int MiniProgramType, final int index, String imgurl) {
            final SimpleDraweeView sdv = (SimpleDraweeView) LayoutInflater.from(getContext())
                    .inflate(R.layout.sdv_home_vip, null, false);
            sdv.setAspectRatio(5.4F);
            sdv.setImageURI(Uri.parse(imgurl));
            sdv.setTag(index);
            // sdv.setOnClickListener(HomeFragment.this);
            sdv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    JumpUtils.jump(getContext(), JumpType, url, jumps, VPListener, MiniAppId, MiniProgramType);
                }
            });

            return sdv;
        }

        @Override
        public int getCount() {
            if (imgData == null) {
                return 0;
            }
            return imgData.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(imgData.get(position));
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(imgData.get(position));
            return imgData.get(position);
        }


    }

    public void setJumps(OrdinaryVipFragment.Jumps jumps) {
        this.jumps = jumps;
    }

    public void setOnControlPageListener(OrdinaryVipFragment.OnViplPageListener listener) {
        this.VPListener = listener;
    }
}
